package leesoft.gocrm.servlet.api;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import leesoft.gocrm.models.ContactDetails;
import leesoft.gocrm.models.dummy.DummyGetAlbum;
import leesoft.gocrm.models.dummy.DummyGetContactDetailsByCode;
import leesoft.gocrm.models.interfaces.IGetAlbum;
import leesoft.gocrm.models.interfaces.IGetContactDetailsByCode;
import leesoft.gocrm.utils.APIError;
import leesoft.gocrm.utils.TextUtils;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class AlbumServlet extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
	{
	    doRequest(request, response);
	}
	
	
	/**
	 * Handle a POST request - calls doRequest()
	 */
	public void doPost(HttpServletRequest request, HttpServletResponse response)
	    throws ServletException, IOException
	{
	    doRequest(request, response);
	}
	
	private void doRequest(HttpServletRequest request, HttpServletResponse response)
	throws ServletException, IOException
	{
		String code=request.getParameter("code");
		String albumId=request.getParameter("albumId");
		if(!TextUtils.isNullOrEmpty(code))
		{
			IGetAlbum albumGetter=new DummyGetAlbum();
			List<String> image_urls=albumGetter.getAlbum(code,albumId);
			JSONArray obj= JSONArray.fromObject(image_urls);
			response.getWriter().print(obj);
		}else
		{
			response.getWriter().print(APIError.ILLEGAL_ARGUMENT);
		}
	}
}
